package cn.xgj.sfzy.controller;

import cn.xgj.sfzy.entity.Appointment;
import cn.xgj.sfzy.entity.Article;
import cn.xgj.sfzy.service.AppointmentService;
import cn.xgj.sfzy.service.ArticleService;
import cn.xgj.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AppointmentController
 * @Description TODO
 * @Author furuyue
 * @Date 2024年10月23日 20:09
 * @Version 1.0
 */

@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @RequestMapping("/findAll")
    public Result findAll(Appointment appointment){
        List<Appointment> list = appointmentService.findAll(appointment);
        return Result.success(list);
    }
    @RequestMapping("/findByPage")
    public Result findByPage(
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "2") Integer pageSize,
            Appointment appointment){
        PageInfo<Appointment> byPage = appointmentService.findByPage(pageNum, pageSize, appointment);
        return Result.success(byPage);
    }

    @DeleteMapping("/{appointmentId}")
    public Result delete(@PathVariable(value = "appointmentId") Integer appointmentId){
        int num = appointmentService.remove(appointmentId);
        if(num!=0){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody Appointment appointment){
        int num = appointmentService.edit(appointment);
        if(num!=0){
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }

    @RequestMapping("/findByUserId")
    public Result findByUserId(Integer userId){
        List<Appointment> list = appointmentService.findByUSerId(userId);
        return Result.success(list);
    }


}
